package hoang.android.app.utility;

import hoang.android.app.R;
import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.view.View;
import android.view.Window;
import android.widget.ImageView;
import android.widget.TextView;

/**
 * 
 * @author Administrator
 * 
 *         build dialog method
 * 
 */
public class SmartDialogUtility extends Dialog {

	private TextView tvTitle, tvMessage;
	private ImageView imgIcon, imgPositiveButton, imgNegativeButton;

	private View.OnClickListener defaultDismiss = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			dismiss();
		}
	};

	private DialogInterface.OnDismissListener positiveDismiss;
	private DialogInterface.OnDismissListener negativeDismiss;

	private View.OnClickListener positiveButtonClick = new View.OnClickListener() {

		@Override
		public void onClick(View v) {

			setOnDismissListener(positiveDismiss);
			dismiss();

		}
	};

	private View.OnClickListener negativeButtonClick = new View.OnClickListener() {

		@Override
		public void onClick(View v) {
			setOnDismissListener(positiveDismiss);
			dismiss();
		}
	};

	public SmartDialogUtility(Context context, int title, int message,
			int positviveButton) {
		super(context);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.positive_custom_dialog);

		tvTitle = (TextView) findViewById(R.id.tvTitleDialog);
		tvTitle.setText(context.getString(title));

		tvMessage = (TextView) findViewById(R.id.tvMessageDialog);
		tvMessage.setText(context.getString(message));

		ImageView imgPositiveButton = (ImageView) findViewById(R.id.btPositiveDialog);
		imgPositiveButton.setBackgroundResource(positviveButton);
		imgPositiveButton.setOnClickListener(defaultDismiss);

	}
	
	public SmartDialogUtility(Context context, String title, String message,
			int positviveButton) {
		super(context);

		requestWindowFeature(Window.FEATURE_NO_TITLE);
		setContentView(R.layout.positive_custom_dialog);

		tvTitle = (TextView) findViewById(R.id.tvTitleDialog);
		tvTitle.setText(title);

		tvMessage = (TextView) findViewById(R.id.tvMessageDialog);
		tvMessage.setText(message);

		ImageView imgPositiveButton = (ImageView) findViewById(R.id.btPositiveDialog);
		imgPositiveButton.setBackgroundResource(positviveButton);
		imgPositiveButton.setOnClickListener(defaultDismiss);

	}
	
	// =========================Standard dialog==================//
	public static void showStandardDialog(Context context, String title,
			int icon, String message, String bt1Name,
			OnClickListener onclickBt1, String bt2Name,
			OnClickListener onclickBt2, String bt3Name,
			OnClickListener onclickBt3) {

		AlertDialog.Builder dialog = new AlertDialog.Builder(context);
		dialog.setIcon(icon);
		dialog.setTitle(title);
		dialog.setMessage(message);

		if (bt1Name != null) {
			dialog.setPositiveButton(bt1Name, onclickBt1);
		}

		if (bt2Name != null) {
			dialog.setNegativeButton(bt2Name, onclickBt2);
		}

		if (bt3Name != null) {
			dialog.setNeutralButton(bt3Name, onclickBt3);
		}

		dialog.show();
	}

	// =========================Custom dialog==================//
}
